package org.ddd.specification.catalog.basic;

import org.apache.commons.lang.ObjectUtils;
import org.ddd.specification.catalog.AbstractSpecification;

/**
 * Checks if a candidate is semantically equal to another value, provided during construction.
 * 
 * @author Jeroen van Schagen
 * @since 2-2-2011
 * 
 * @param <T> type of candidates being verified
 */
public class EqualToSpecification<T> extends AbstractSpecification<T> {
    private final Object value;

    /**
     * Construct a new {@link EqualToSpecification}.
     * @param value the value that our candidates should be equal to
     */
    public EqualToSpecification(Object value) {
        this.value = value;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isSatisfiedBy(T candidate) {
        return ObjectUtils.equals(candidate, value);
    }

}
